<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #box{
            width: 300px;
            height: 300px;
            border: 1px solid #ccc;
            margin: 100px auto;
        }
        .bgRed{
            background: red;
        }
        .bgGreen{
            background: green;
        }
    </style>
</head>
<body>
<input type="button"value="变红"id="btn1">
<input type="button"value="变绿"id="btn2">
<div id="box"></div>
</body>
</html>
<script>
    var oBtn1 = document.getElementById("btn1");
    var oBtn2 = document.getElementById("btn2");
    var oBox = document.getElementById("box");
    //变红
    oBtn1.onclick = function () {
        oBox.className = "bgRed";
    }
    //变绿
    oBtn2.onclick = function () {
        oBox.className = "bgGreen";
    }
</script>